{extend name="normal_base" /}
{block name="css"}
<style>

</style>
{/block}
{block name="body"}
<div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="javascript:location.replace(location.href);">刷新</button>
        <button class="layui-btn layui-btn-normal" onclick="x_admin_show('添加项目组','{:url(\'add\')}', 700, 300)">添加</button>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">批量删除</button>
    </xblock>

    <table class="layui-table" lay-size="">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>项目组名称</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach name="list" item="vo"}
        <tr class="customer-tr" data-id='{$vo.id}'>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td class="can-click show-contract">{$vo.group_name}</td>
            <td class="td-manage">
                <a title="编辑"  onclick="x_admin_show('编辑项目组','edit/id/{$vo.id}', 700, 300)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>&nbsp;

                <a title="删除" onclick="delOne(this,{$vo.id})" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    <!--分页-->
    {$list->render()}
</div>

{/block}

{block name="script"}
<script src="__JS__/jquery.fileDownload.js"></script>
<script>
    layui.use(['layer'], function(){
        var laydate = layui.laydate;
        var element = layui.element;

        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;
    });

    /*删除*/
    function delOne(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.ajax({
                type: "post",
                url: "delete?ids="+id,
                dataType: "json",
                success: function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg);
                    } else {
                        layer.msg('已删除!',{icon:1,time:1000});
                        $(obj).parents("tr").remove();
                    }
                }, error: function(){
                    layer.msg("请求出错",{icon:5,time:1000});
                }
            });
        });
    }

    /*删除*/
    function delAll (argument) {
        //获取选中的id
        var data = tableCheck.getData();
        if (data.length > 0) {
            layer.confirm('确认要删除吗？',function(index){
                var success = 0;
                //捉到所有被选中的，发异步进行删除
                $.ajax({
                    type: "post",
                    url: "delete?ids="+data.join(','),
                    dataType: "json",
                    success: function(data){
                        if (data.code == 1) {
                            layer.msg(data.msg,{icon:5,time:1500});
                        } else {
                            layer.msg('已删除!',{icon:1,time:1000});
                            success = 1
                        }
                    }, error: function(){
                        layer.msg("请求出错",{icon:5,time:1000});
                    }
                });

                setTimeout(function () {
                    location.replace(location.href);
                }, 1500);
            });
        } else {
            layer.msg("您还未勾选要删除的数据",{icon:5,time:1500});
        }
    }
</script>
{/block}